import Vue from "vue";
import VueRouter from "vue-router";
import Leader from "../views/LeaderView.vue";

Vue.use(VueRouter);

// 防止重复跳转
let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject);
  } else {
    originPush.call(
      this,
      location,
      () => { },
      () => { }
    );
  }
};
// 防止重复跳转
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.relace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject);
  } else {
    originReplace.call(
      this,
      location,
      () => { },
      () => { }
    );
  }
};

const routes = [
  {
    path: "*",
    name: "notFound",
    component: () => import("../views/notFound.vue"),
  },
  {
    path: "/",
    redirect: "/leader/index",
  },

  {
    path: "/leader",
    name: "leader",
    component: Leader,
    children: [
      {
        path: "index",
        component: () => import("../views/IndexView.vue"),
        meta: {
          keepAlive: true, // 自定义属性，通过该属性动态设置保活
        },
      },
      {
        path: "me",
        name: "me",
        component: () => import("../views/me.vue"),
      },
      {
        path: "news_index",
        name: "news_index",
        props: (route) => ({
          classid: route.params.classid,
        }),
        component: () => import("../views/NewsIndex.vue"),
      },
    ],
  },
  {
    path: "/doctor",
    name: "doctor",
    component: () => import("../views/doctorList/index.vue"),
    redirect: "/doctor/list",
    children: [
      {
        path: "list",
        component: () => import("../views/doctorList/list/index.vue"),
      },
      {
        path: "detail/:id",
        name:"doctorListDetail",
        component: () => import("../views/doctorList/details/index.vue"),
      },
    ],
  },
  {
    path: "/updateupwd",
    name: "updateupwd",
    component: () => import("../views/UpdateUpwView.vue"),
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("../views/RegisterView.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/LoginView.vue"),
  },
  // 活动详情页
  {
    path: "/content",
    name: "content",
    component: () => import("../views/ConTent.vue"),
  },
  // 活动标题页（可忽略  不可删除）
  {
    path: "/detail",
    name: "detail",
    component: () => import("../components/detail.vue"),
  },
  // 活动标题页
  {
    path: "/homeview",
    name: "homeview",
    component: () => import("../views/HomeView.vue"),
    meta: {
      KeepAlive: true, // 保活路由
    },
  },
  {
    path: '/gobuyvip',
    name: 'goBuyVip',
    component: () => import('../views/GoBuyVip.vue'),
  },
  {
    path: '/collectlist',
    name: 'collectList',
    component: () => import('../views/CollectList.vue'),
  },
  {
    path: "/updatemsg",
    name: "updateMsg",
    component: () => import("../views/updateMsg.vue"),
  },
  {
    path: "/detailsList",
    name: "detailsList",
    component: () => import("../views/DetailsList.vue"),
  },
  {
    path: "/clinicDetails",
    name: "clinicDetails",
    component: () => import("../views/ClinicDetails.vue"),
  },
  {
    path: "/clinicReg",
    name: "clinicReg",
    component: () => import("../views/ClinicReg.vue"),
  },
  {
    path: "/customer",
    name: "customer",
    component: () => import("../views/CuStomer.vue"),
  },
  {
    path: "/addrlist/:provinceId/:cityId",
    name: "addrlist",
    props: (route) => ({
      provinceId: route.params.provinceId,
      cityId: route.params.cityId,
    }),
    component: () => import("../views/AddrList.vue"),
  },
  {
    path: "/map_container/:id",
    name: "map_container",
    props: (route) => ({
      longitude: route.params.id,
    }),
    component: () => import("../views/MapContainer.vue"),
  },
  {
    path: "/news_details/:id",
    name: "news_details",
    props: (route) => ({
      id: route.params.id,
    }),
    component: () => import("../views/NewsDetails.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
